package com.ihr360.payroll.model.dto.salary.report;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ihr360.payroll.model.response.salaryreport.SalaryHeader;
import com.ihr360.payroll.type.ReportState;
import com.ihr360.shared.entitywithlistener.NumberIdWithTimeAndCompanyId;
import org.hibernate.annotations.Type;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Index;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import java.util.Date;
import java.util.List;

/**
 * Created by Eric on 2018/4/12/012.
 */

/**
 * 合并报表临时结果
 */
@Entity
@Table(
        indexes = {@Index(name = "company_index", columnList = "companyId,mergeReportId,year,month,indexno", unique = true)})
//@DynamicUpdate
public class MergeSalaryReportTermSalary extends NumberIdWithTimeAndCompanyId<Long> {

    /**
     * 对应的合并报表id
     */
    private Long mergeReportId;

    /**
     * 对应的合并报表日期
     */
    @Column(nullable = false, columnDefinition = "DATE")
    private Date termDate;

    private int year;

    private int month;

    /**
     * 对应的批次
     */
    private Integer indexno;


    /**
     * 状态
     */
    @Column(length = 10)
    @Enumerated(value = EnumType.STRING)
    private ReportState reportState;

    /**
     * 表头信息
     */
    @Column(columnDefinition = "text", name = "mergeSalaryField")
    @Type(type = "json")
    private SalaryHeader salaryHeader;

    @OneToMany(mappedBy = "termSalary", cascade = CascadeType.ALL, orphanRemoval = true)
    @OrderBy("createdAt desc")
    private List<MergeReportStaffSalary> staffSalaryList;

    /**
     * 备注信息
     */
    @Column(length = 100)
    private String remark;

    public MergeSalaryReportTermSalary() {
    }

    public MergeSalaryReportTermSalary(Long id) {
        this.id = id;
    }

    public MergeSalaryReportTermSalary(Long mergeReportId, Date termDate, Integer indexno) {
        this.mergeReportId = mergeReportId;
        this.termDate = termDate;
        this.indexno = indexno;
    }

    public Long getMergeReportId() {
        return mergeReportId;
    }

    public void setMergeReportId(Long mergeReportId) {
        this.mergeReportId = mergeReportId;
    }

    public Date getTermDate() {
        return termDate;
    }

    public void setTermDate(Date termDate) {
        this.termDate = termDate;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public Integer getIndexno() {
        return indexno;
    }

    public void setIndexno(Integer indexno) {
        this.indexno = indexno;
    }

    public SalaryHeader getSalaryHeader() {
        return salaryHeader;
    }

    public void setSalaryHeader(SalaryHeader salaryHeader) {
        this.salaryHeader = salaryHeader;
    }

    public ReportState getReportState() {
        return reportState;
    }

    public void setReportState(ReportState reportState) {
        this.reportState = reportState;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @JsonIgnore
    public List<MergeReportStaffSalary> getStaffSalaryList() {
        return staffSalaryList;
    }

    public void setStaffSalaryList(List<MergeReportStaffSalary> staffSalaryList) {
        this.staffSalaryList = staffSalaryList;
    }
}
